package com.swanclouds.redfish.event.domain;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.swanclouds.model.event.Event;
import com.swanclouds.redfish.common.redfish.Status;

import java.util.List;
import java.util.Map;

/**
 * @author 李文强
 * description 事件资源服务实体类
 */
public class EventModel implements Event {
    //事件资源服务模型的OData描述信息
    @JsonProperty("@odata.context")
    private String context;

    //事件资源服务模型的电子标签
    @JsonProperty("@odata.etag")
    private String etag;

    //事件资源服务模型的id
    @JsonProperty("@odata.id")
    private String dataId;

    //事件资源服务模型的类型
    @JsonProperty("@odata.type")
    private String type;

    //事件服务资源的可操作资源属性
    @JsonProperty("Actions")
    private Map<String,Object> actions;

    //事件订阅发送失败最大尝试次数
    @JsonProperty("DeliveryRetryAttempts")
    private Integer DeliveryRetryAttempts;

    //发送任何给定事件的重试尝试之间的秒数
    @JsonProperty("DeliveryRetryIntervalSeconds")
    private Integer deliveryRetryIntervalSeconds;

    //事件服务资源的描述信息
    @JsonProperty("Description")
    private String description;

    /**
     * 指可以订阅的事件的类型，取值为以下合法的
     * 组合：
     * StatusChange：资源状态改变事件
     *  ResourceUpdated：资
     * 源更新事件
     *  ResourceAdded：资源
     * 添加事件
     *  ResourceRemoved：资源移除事件
     * Alert：告警事件
     */
    @JsonProperty("EventTypesForSubscription")
    private List<String> eventTypesForSubscription;

    //事件服务资源的id
    @JsonProperty("Id")
    private String id;

    //事件服务资源的名称
    @JsonProperty("Name")
    private String name;

    //事件服务使能状态
    @JsonProperty("ServiceEnabled")
    private Boolean serviceEnabled;

    /**
     * State: 事件服务资源的使能状态
     * Health: 事件服务资源的健康状态
     */
    @JsonProperty("Status")
    private List<Status> status;

    //目标资源的集合的导航资源
    @JsonProperty("Subscriptions")
    private List<Map<String,Object>> subscriptions;

    @Override
    public String getDataId() {
        return this.dataId;
    }

    @Override
    public String getContext() {
        return this.context;
    }

    @Override
    public String getType() {
        return this.type;
    }

    @Override
    public String getId() {
        return this.id;
    }

    @Override
    public String getName() {
        return this.name;
    }

    @Override
    public Map<String, Object> getAction() {
        return this.actions;
    }

    public String getEtag() {
        return etag;
    }

    public Map<String, Object> getActions() {
        return actions;
    }

    public Integer getDeliveryRetryAttempts() {
        return DeliveryRetryAttempts;
    }

    public Integer getDeliveryRetryIntervalSeconds() {
        return deliveryRetryIntervalSeconds;
    }

    public String getDescription() {
        return description;
    }

    public List<String> getEventTypesForSubscription() {
        return eventTypesForSubscription;
    }

    public Boolean getServiceEnabled() {
        return serviceEnabled;
    }

    public List<Status> getStatus() {
        return status;
    }

    public List<Map<String, Object>> getSubscriptions() {
        return subscriptions;
    }

    @Override
    public String toString() {
        ObjectMapper objectMapper = new ObjectMapper();
        try {
            return objectMapper.writeValueAsString(this);
        } catch (JsonProcessingException e) {
        }
        return "EventModel{" +
                "context='" + context + '\'' +
                ", etag='" + etag + '\'' +
                ", dataId='" + dataId + '\'' +
                ", type='" + type + '\'' +
                ", actions=" + actions +
                ", DeliveryRetryAttempts='" + DeliveryRetryAttempts + '\'' +
                ", deliveryRetryIntervalSeconds='" + deliveryRetryIntervalSeconds + '\'' +
                ", description='" + description + '\'' +
                ", eventTypesForSubscription=" + eventTypesForSubscription +
                ", id='" + id + '\'' +
                ", name='" + name + '\'' +
                ", serviceEnabled='" + serviceEnabled + '\'' +
                ", status=" + status +
                ", Subscriptions=" + subscriptions +
                '}';
    }
}
